package org.openfans.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.openfans.domain.Facade;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class MainController extends AbstractController {
	private Facade facade = null;

	public void setFacade(Facade facade) {
		this.facade = facade;
	}

	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		List tags = facade.getPagedTags(1, 40, "title asc");
		map.put("tags", tags);
		List recentNews = facade.getRecentArticles(10, "articleId desc",
				"News");
		map.put("recentNews", recentNews);

		List recentTechArticles = facade.getRecentArticles(20,
				"articleId desc", "TechArticle");
		map.put("recentTechArticles", recentTechArticles);

		List recentRootTags = facade.getRecentRootTags(8, "tagId desc");
		map.put("recentRootTags", recentRootTags);
//		List recommendRootTags = facade.getRecommendRootTags();
//		map.put("recommendRootTags", recommendRootTags);
		List recentFans = facade.getRecentFans(10, "hot desc");
		map.put("recentFans", recentFans);
		List recentGroups = facade.getPagedGroups(1, 10, "hot desc");
		map.put("recentGroups", recentGroups);
		List recentBoardItem = facade.getRecentBoardItem(3);
		map.put("recentBoardItem", recentBoardItem);
		return new ModelAndView("public/main", map);
	}

}
